Load packages
library(data.table) # For faster data manipulation
library(tidyverse) # For data manipulation and visualization
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between() masks data.table::between()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::first() masks data.table::first()
## ✖ lubridate::hour() masks data.table::hour()
## ✖ lubridate::isoweek() masks data.table::isoweek()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::last() masks data.table::last()
## ✖ lubridate::mday() masks data.table::mday()
## ✖ lubridate::minute() masks data.table::minute()
## ✖ lubridate::month() masks data.table::month()
## ✖ lubridate::quarter() masks data.table::quarter()
## ✖ lubridate::second() masks data.table::second()
## ✖ purrr::transpose() masks data.table::transpose()
## ✖ lubridate::wday() masks data.table::wday()
## ✖ lubridate::week() masks data.table::week()
## ✖ lubridate::yday() masks data.table::yday()
## ✖ lubridate::year() masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sf) # For spatial data handling
## Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(leaflet) # For interactive maps
library(leaflet.extras) # For additional leaflet features
library(mapview) # For easier map visualization
library(tmap) # For thematic maps
library(tigris) # For US road networks
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(future) # For parallel processing
library(future.apply) # For parallel processing with apply functions
library(sf) # For spatial data handling
# Remove PostgreSQL packages as we're not using them anymore
# library(RPostgres) # For PostgreSQL connection
# library(DBI) # For database interface
# Create directories if they don't exist
if (!dir.exists("./data/tigris")) {
dir.create("./data/tigris", recursive = TRUE)
}
# Set custom cache directory (optional)
options(tigris_cache_dir = "./data/tigris")
# Configure tigris to use caching
options(tigris_use_cache = TRUE)
# Function to create buffers in batches with proper projection
create_buffers_in_batches <- function(sf_object, buffer_dist, batch_size = 500) {
# First, reproject to an appropriate projected CRS for the region
# For California, UTM Zone 10N (EPSG:26910) or 11N (EPSG:26911) works well
# If we're unsure about your region, a web mercator projection (3857) is a reasonable default
message("Reprojecting data to a meter-based CRS...")
sf_object_projected <- st_transform(sf_object, 3310) # California Albers
n_features <- nrow(sf_object_projected)
n_batches <- ceiling(n_features / batch_size)
# Create empty list to store results
buffer_list <- vector("list", n_batches)
# Process in batches
for (i in 1:n_batches) {
start_idx <- (i-1) * batch_size + 1
end_idx <- min(i * batch_size, n_features)
cat(sprintf("Processing batch %d of %d (features %d to %d)\n",
i, n_batches, start_idx, end_idx))
# Extract batch
batch <- sf_object_projected[start_idx:end_idx, ]
# Create buffer (with parallel processing within sf)
buffer_list[[i]] <- st_buffer(batch, dist = buffer_dist)
}
# Combine results
result <- do.call(rbind, buffer_list)
# Reproject back to original CRS if needed
message("Reprojecting results back to original CRS...")
st_transform(result, st_crs(sf_object))
}
Load data (filter for California for now to limit data set size)
# Efficient approach
df.acc <- fread("data/us_accidents/US_accidents_March23.csv")[
# Filter date range of 2021
lubridate::year(as.Date(Start_Time)) == 2021 &
# And California
State == "CA"
][, `:=`(
# Add year, quarter, month columns
year = data.table::year(Start_Time),
quarter = data.table::quarter(Start_Time),
month = data.table::month(Start_Time),
# Calculate duration (assuming End_Time exists in the dataset)
duration = as.numeric(difftime(End_Time, Start_Time, units = "days"))
)] %>%
as_tibble() # Convert to tibble only at the end for performance
df.const <- fread("data/us_constructions/US_constructions_Dec21.csv")[
# Filter date range of 2021
lubridate::year(as.Date(Start_Time)) == 2021 &
# And California
State == "CA"
][, `:=`(
# Add year, quarter, month columns
year = year(Start_Time),
quarter = quarter(Start_Time),
month = month(Start_Time),
# Calculate duration (assuming End_Time exists in the dataset)
duration = as.numeric(difftime(End_Time, Start_Time, units = "days"))
)] %>%
as_tibble() # Convert to tibble only at the end for performance
Convert dataframes to sf objects
# Convert accident data to sf object
df.acc.sf <- df.acc %>%
filter(!is.na(Start_Lat) & !is.na(Start_Lng)) %>%
st_as_sf(coords = c("Start_Lng", "Start_Lat"), crs = 4326)
# Convert construction data to sf object
df.const.sf <- df.const %>%
filter(!is.na(Start_Lat) & !is.na(Start_Lng)) %>%
st_as_sf(coords = c("Start_Lng", "Start_Lat"), crs = 4326)
# Get US roads (this can be slow for the entire US, so we might want to limit by state)
# We also only get Primary and Secondary roads as they are the most important (i.e., where most constructions and accidents happen). Otherwise, the dataset would become to large (1.1GB)
ca_roads <- primary_secondary_roads("CA", year = 2021)
# Below code to get ALL roads for California (not recommended due to size)
# First get all counties in California
#ca_counties <- counties("CA", year = 2021)
# Then get roads for each county
#ca_roads_list <- lapply(ca_counties$COUNTYFP, function(county_code) {
# roads("CA", county = county_code, year = 2021)
#})
# Optionally combine all county road data into one object
#ca_roads <- do.call(rbind, ca_roads_list)
# Static map for Accidents with year coloring
# First, store your plot in a variable
ca_plot <- ggplot() +
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
geom_sf(data = df.acc.sf %>% filter(State == "CA"),
aes(color = factor(year)), alpha = 0.7, size = 0.5) +
scale_color_viridis_d(name = "Year") + # Use viridis color palette for discrete values
theme_minimal() +
labs(title = "US Road Accidents by Year (2016-2021)") +
theme(legend.position = "bottom")
print(ca_plot)

# Then save it using ggsave
ggsave(filename = "imgs/california_accidents.png",
plot = ca_plot,
width = 10, # width in inches
height = 8, # height in inches
dpi = 300) # resolution
# Construction sites map with year coloring
# First, store our plot in a variable
ca_const_plot <- ggplot() +
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
geom_sf(data = df.const.sf %>% filter(State == "CA"),
aes(color = factor(year)), alpha = 0.7, size = 0.5) +
scale_color_viridis_d(name = "Year") + # Use viridis color palette for discrete values
theme_minimal() +
labs(title = "US Construction Sites by Year (2016-2021)") +
theme(legend.position = "bottom")
print(ca_const_plot)

# Then save it using ggsave
ggsave(filename = "imgs/california_construction.png",
plot = ca_const_plot,
width = 10, # width in inches
height = 8, # height in inches
dpi = 300) # resolution
# Create heatmap of accidents using ggplot2
# Modified accident heatmap with transparency for low density areas
accident_heatmap <- ggplot() +
# Add California roads as base layer
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
# Create density heatmap with transparency threshold
stat_density_2d(
data = df.acc %>% filter(!is.na(Start_Lat) & !is.na(Start_Lng)),
aes(x = Start_Lng, y = Start_Lat, fill = after_stat(density), alpha = after_stat(density)),
geom = "tile",
contour = FALSE,
h = 0.1,
n = 200
) +
# Set alpha scaling with a minimum threshold
scale_alpha_continuous(range = c(0, 0.9), guide = "none") +
# Use color scheme similar to leaflet's default heatmap
scale_fill_gradientn(
colors = c("#0000FF", "#00FFFF", "#00FF00", "#FFFF00", "#FF0000"),
name = "Accident\nDensity"
) +
coord_sf(
xlim = c(-124.5, -114.5),
ylim = c(32.5, 42.5)
) +
theme_minimal() +
labs(
title = "Accident Density Heatmap in California (2016-2021)",
x = NULL,
y = NULL
) +
theme(
legend.position = "right",
plot.title = element_text(face = "bold")
)
# Display the plot
print(accident_heatmap)

ggsave(filename = "imgs/accident_heatmap.png",
plot = accident_heatmap,
width = 10, # width in inches
height = 8, # height in inches
dpi = 300) # resolution
# Create heatmap of construction sites using ggplot2
construction_heatmap <- ggplot() +
# Add California roads as base layer
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
# Create density heatmap
stat_density_2d(
data = df.const %>% filter(!is.na(Start_Lat) & !is.na(Start_Lng)),
aes(x = Start_Lng, y = Start_Lat, fill = after_stat(density)),
geom = "tile",
contour = FALSE,
alpha = 0.7,
h = 0.1, # Bandwidth
n = 200 # Resolution
) +
# Set alpha scaling with a minimum threshold
scale_alpha_continuous(range = c(0, 0.9), guide = "none") +
# Use color scheme matching your leaflet construction map
scale_fill_gradientn(
colors = c("yellow", "orange", "red"),
name = "Construction\nDensity"
) +
# Set appropriate boundaries for California
coord_sf(
xlim = c(-124.5, -114.5),
ylim = c(32.5, 42.5)
) +
theme_minimal() +
labs(
title = "Construction Density Heatmap in California (2016-2021)",
x = NULL,
y = NULL
) +
theme(
legend.position = "right",
plot.title = element_text(face = "bold")
)
# Display the plot
print(construction_heatmap)

# For interactive maps (often better for large datasets)
# Accidents map
accident_map <- leaflet() %>%
addTiles() %>%
addHeatmap(data = df.acc.sf,
intensity = ~1,
radius = 8,
blur = 10) %>%
setView(lng = -119.4179, lat = 36.7783, zoom = 6) %>% # Center to CA
setMaxBounds(lng1 = -124.6, lat1 = 42.0, # Northwest corner of CA
lng2 = -114.1, lat2 = 32.5) # Southeast corner of CA
# Display maps
accident_map
# Construction sites map with California focus and bounds constraints
construction_map <- leaflet() %>%
addTiles() %>%
addHeatmap(data = df.const.sf,
intensity = ~1,
radius = 8,
blur = 10,
gradient = c("yellow", "orange", "red")) %>%
setView(lng = -119.4179, lat = 36.7783, zoom = 6) %>% # Center on California
setMaxBounds(lng1 = -124.6, lat1 = 42.0, # Northwest corner of CA
lng2 = -114.1, lat2 = 32.5) # Southeast corner of CA
# Display the map
construction_map
We construct construction sites now also as line objects since they have a start and end point
# Convert construction data to linestring sf object
df.const.lines <- df.const %>%
filter(!is.na(Start_Lat) & !is.na(Start_Lng) & !is.na(End_Lat) & !is.na(End_Lng)) %>%
mutate(geometry = pmap(list(Start_Lng, Start_Lat, End_Lng, End_Lat),
function(start_lng, start_lat, end_lng, end_lat) {
coords <- matrix(c(start_lng, start_lat,
end_lng, end_lat),
ncol = 2, byrow = TRUE)
st_linestring(coords)
})) %>%
st_sf(crs = 4326)
# Set up parallel processing to speed up computations
future::plan(future::multisession, workers = parallel::detectCores() - 1)
cat("Creating construction buffers...\n")
## Creating construction buffers...
# Step 1A: Create construction point buffers
# Transform to meter-based CRS, buffer, and transform back
construction_buffers <- df.const.sf %>%
# Add ID as a primary key if it doesn't exist
mutate(construction_id = if("ID" %in% names(.)) ID else row_number()) %>%
# Select only needed columns
select(construction_id, Start_Time, End_Time, geometry) %>%
# Rename columns to match our schema
rename(start_time = Start_Time, end_time = End_Time) %>%
# Create the buffer using our batch function
create_buffers_in_batches(buffer_dist = 300, batch_size = 500)
## Reprojecting data to a meter-based CRS...
## Processing batch 1 of 407 (features 1 to 500)
## Processing batch 2 of 407 (features 501 to 1000)
## Processing batch 3 of 407 (features 1001 to 1500)
## Processing batch 4 of 407 (features 1501 to 2000)
## Processing batch 5 of 407 (features 2001 to 2500)
## Processing batch 6 of 407 (features 2501 to 3000)
## Processing batch 7 of 407 (features 3001 to 3500)
## Processing batch 8 of 407 (features 3501 to 4000)
## Processing batch 9 of 407 (features 4001 to 4500)
## Processing batch 10 of 407 (features 4501 to 5000)
## Processing batch 11 of 407 (features 5001 to 5500)
## Processing batch 12 of 407 (features 5501 to 6000)
## Processing batch 13 of 407 (features 6001 to 6500)
## Processing batch 14 of 407 (features 6501 to 7000)
## Processing batch 15 of 407 (features 7001 to 7500)
## Processing batch 16 of 407 (features 7501 to 8000)
## Processing batch 17 of 407 (features 8001 to 8500)
## Processing batch 18 of 407 (features 8501 to 9000)
## Processing batch 19 of 407 (features 9001 to 9500)
## Processing batch 20 of 407 (features 9501 to 10000)
## Processing batch 21 of 407 (features 10001 to 10500)
## Processing batch 22 of 407 (features 10501 to 11000)
## Processing batch 23 of 407 (features 11001 to 11500)
## Processing batch 24 of 407 (features 11501 to 12000)
## Processing batch 25 of 407 (features 12001 to 12500)
## Processing batch 26 of 407 (features 12501 to 13000)
## Processing batch 27 of 407 (features 13001 to 13500)
## Processing batch 28 of 407 (features 13501 to 14000)
## Processing batch 29 of 407 (features 14001 to 14500)
## Processing batch 30 of 407 (features 14501 to 15000)
## Processing batch 31 of 407 (features 15001 to 15500)
## Processing batch 32 of 407 (features 15501 to 16000)
## Processing batch 33 of 407 (features 16001 to 16500)
## Processing batch 34 of 407 (features 16501 to 17000)
## Processing batch 35 of 407 (features 17001 to 17500)
## Processing batch 36 of 407 (features 17501 to 18000)
## Processing batch 37 of 407 (features 18001 to 18500)
## Processing batch 38 of 407 (features 18501 to 19000)
## Processing batch 39 of 407 (features 19001 to 19500)
## Processing batch 40 of 407 (features 19501 to 20000)
## Processing batch 41 of 407 (features 20001 to 20500)
## Processing batch 42 of 407 (features 20501 to 21000)
## Processing batch 43 of 407 (features 21001 to 21500)
## Processing batch 44 of 407 (features 21501 to 22000)
## Processing batch 45 of 407 (features 22001 to 22500)
## Processing batch 46 of 407 (features 22501 to 23000)
## Processing batch 47 of 407 (features 23001 to 23500)
## Processing batch 48 of 407 (features 23501 to 24000)
## Processing batch 49 of 407 (features 24001 to 24500)
## Processing batch 50 of 407 (features 24501 to 25000)
## Processing batch 51 of 407 (features 25001 to 25500)
## Processing batch 52 of 407 (features 25501 to 26000)
## Processing batch 53 of 407 (features 26001 to 26500)
## Processing batch 54 of 407 (features 26501 to 27000)
## Processing batch 55 of 407 (features 27001 to 27500)
## Processing batch 56 of 407 (features 27501 to 28000)
## Processing batch 57 of 407 (features 28001 to 28500)
## Processing batch 58 of 407 (features 28501 to 29000)
## Processing batch 59 of 407 (features 29001 to 29500)
## Processing batch 60 of 407 (features 29501 to 30000)
## Processing batch 61 of 407 (features 30001 to 30500)
## Processing batch 62 of 407 (features 30501 to 31000)
## Processing batch 63 of 407 (features 31001 to 31500)
## Processing batch 64 of 407 (features 31501 to 32000)
## Processing batch 65 of 407 (features 32001 to 32500)
## Processing batch 66 of 407 (features 32501 to 33000)
## Processing batch 67 of 407 (features 33001 to 33500)
## Processing batch 68 of 407 (features 33501 to 34000)
## Processing batch 69 of 407 (features 34001 to 34500)
## Processing batch 70 of 407 (features 34501 to 35000)
## Processing batch 71 of 407 (features 35001 to 35500)
## Processing batch 72 of 407 (features 35501 to 36000)
## Processing batch 73 of 407 (features 36001 to 36500)
## Processing batch 74 of 407 (features 36501 to 37000)
## Processing batch 75 of 407 (features 37001 to 37500)
## Processing batch 76 of 407 (features 37501 to 38000)
## Processing batch 77 of 407 (features 38001 to 38500)
## Processing batch 78 of 407 (features 38501 to 39000)
## Processing batch 79 of 407 (features 39001 to 39500)
## Processing batch 80 of 407 (features 39501 to 40000)
## Processing batch 81 of 407 (features 40001 to 40500)
## Processing batch 82 of 407 (features 40501 to 41000)
## Processing batch 83 of 407 (features 41001 to 41500)
## Processing batch 84 of 407 (features 41501 to 42000)
## Processing batch 85 of 407 (features 42001 to 42500)
## Processing batch 86 of 407 (features 42501 to 43000)
## Processing batch 87 of 407 (features 43001 to 43500)
## Processing batch 88 of 407 (features 43501 to 44000)
## Processing batch 89 of 407 (features 44001 to 44500)
## Processing batch 90 of 407 (features 44501 to 45000)
## Processing batch 91 of 407 (features 45001 to 45500)
## Processing batch 92 of 407 (features 45501 to 46000)
## Processing batch 93 of 407 (features 46001 to 46500)
## Processing batch 94 of 407 (features 46501 to 47000)
## Processing batch 95 of 407 (features 47001 to 47500)
## Processing batch 96 of 407 (features 47501 to 48000)
## Processing batch 97 of 407 (features 48001 to 48500)
## Processing batch 98 of 407 (features 48501 to 49000)
## Processing batch 99 of 407 (features 49001 to 49500)
## Processing batch 100 of 407 (features 49501 to 50000)
## Processing batch 101 of 407 (features 50001 to 50500)
## Processing batch 102 of 407 (features 50501 to 51000)
## Processing batch 103 of 407 (features 51001 to 51500)
## Processing batch 104 of 407 (features 51501 to 52000)
## Processing batch 105 of 407 (features 52001 to 52500)
## Processing batch 106 of 407 (features 52501 to 53000)
## Processing batch 107 of 407 (features 53001 to 53500)
## Processing batch 108 of 407 (features 53501 to 54000)
## Processing batch 109 of 407 (features 54001 to 54500)
## Processing batch 110 of 407 (features 54501 to 55000)
## Processing batch 111 of 407 (features 55001 to 55500)
## Processing batch 112 of 407 (features 55501 to 56000)
## Processing batch 113 of 407 (features 56001 to 56500)
## Processing batch 114 of 407 (features 56501 to 57000)
## Processing batch 115 of 407 (features 57001 to 57500)
## Processing batch 116 of 407 (features 57501 to 58000)
## Processing batch 117 of 407 (features 58001 to 58500)
## Processing batch 118 of 407 (features 58501 to 59000)
## Processing batch 119 of 407 (features 59001 to 59500)
## Processing batch 120 of 407 (features 59501 to 60000)
## Processing batch 121 of 407 (features 60001 to 60500)
## Processing batch 122 of 407 (features 60501 to 61000)
## Processing batch 123 of 407 (features 61001 to 61500)
## Processing batch 124 of 407 (features 61501 to 62000)
## Processing batch 125 of 407 (features 62001 to 62500)
## Processing batch 126 of 407 (features 62501 to 63000)
## Processing batch 127 of 407 (features 63001 to 63500)
## Processing batch 128 of 407 (features 63501 to 64000)
## Processing batch 129 of 407 (features 64001 to 64500)
## Processing batch 130 of 407 (features 64501 to 65000)
## Processing batch 131 of 407 (features 65001 to 65500)
## Processing batch 132 of 407 (features 65501 to 66000)
## Processing batch 133 of 407 (features 66001 to 66500)
## Processing batch 134 of 407 (features 66501 to 67000)
## Processing batch 135 of 407 (features 67001 to 67500)
## Processing batch 136 of 407 (features 67501 to 68000)
## Processing batch 137 of 407 (features 68001 to 68500)
## Processing batch 138 of 407 (features 68501 to 69000)
## Processing batch 139 of 407 (features 69001 to 69500)
## Processing batch 140 of 407 (features 69501 to 70000)
## Processing batch 141 of 407 (features 70001 to 70500)
## Processing batch 142 of 407 (features 70501 to 71000)
## Processing batch 143 of 407 (features 71001 to 71500)
## Processing batch 144 of 407 (features 71501 to 72000)
## Processing batch 145 of 407 (features 72001 to 72500)
## Processing batch 146 of 407 (features 72501 to 73000)
## Processing batch 147 of 407 (features 73001 to 73500)
## Processing batch 148 of 407 (features 73501 to 74000)
## Processing batch 149 of 407 (features 74001 to 74500)
## Processing batch 150 of 407 (features 74501 to 75000)
## Processing batch 151 of 407 (features 75001 to 75500)
## Processing batch 152 of 407 (features 75501 to 76000)
## Processing batch 153 of 407 (features 76001 to 76500)
## Processing batch 154 of 407 (features 76501 to 77000)
## Processing batch 155 of 407 (features 77001 to 77500)
## Processing batch 156 of 407 (features 77501 to 78000)
## Processing batch 157 of 407 (features 78001 to 78500)
## Processing batch 158 of 407 (features 78501 to 79000)
## Processing batch 159 of 407 (features 79001 to 79500)
## Processing batch 160 of 407 (features 79501 to 80000)
## Processing batch 161 of 407 (features 80001 to 80500)
## Processing batch 162 of 407 (features 80501 to 81000)
## Processing batch 163 of 407 (features 81001 to 81500)
## Processing batch 164 of 407 (features 81501 to 82000)
## Processing batch 165 of 407 (features 82001 to 82500)
## Processing batch 166 of 407 (features 82501 to 83000)
## Processing batch 167 of 407 (features 83001 to 83500)
## Processing batch 168 of 407 (features 83501 to 84000)
## Processing batch 169 of 407 (features 84001 to 84500)
## Processing batch 170 of 407 (features 84501 to 85000)
## Processing batch 171 of 407 (features 85001 to 85500)
## Processing batch 172 of 407 (features 85501 to 86000)
## Processing batch 173 of 407 (features 86001 to 86500)
## Processing batch 174 of 407 (features 86501 to 87000)
## Processing batch 175 of 407 (features 87001 to 87500)
## Processing batch 176 of 407 (features 87501 to 88000)
## Processing batch 177 of 407 (features 88001 to 88500)
## Processing batch 178 of 407 (features 88501 to 89000)
## Processing batch 179 of 407 (features 89001 to 89500)
## Processing batch 180 of 407 (features 89501 to 90000)
## Processing batch 181 of 407 (features 90001 to 90500)
## Processing batch 182 of 407 (features 90501 to 91000)
## Processing batch 183 of 407 (features 91001 to 91500)
## Processing batch 184 of 407 (features 91501 to 92000)
## Processing batch 185 of 407 (features 92001 to 92500)
## Processing batch 186 of 407 (features 92501 to 93000)
## Processing batch 187 of 407 (features 93001 to 93500)
## Processing batch 188 of 407 (features 93501 to 94000)
## Processing batch 189 of 407 (features 94001 to 94500)
## Processing batch 190 of 407 (features 94501 to 95000)
## Processing batch 191 of 407 (features 95001 to 95500)
## Processing batch 192 of 407 (features 95501 to 96000)
## Processing batch 193 of 407 (features 96001 to 96500)
## Processing batch 194 of 407 (features 96501 to 97000)
## Processing batch 195 of 407 (features 97001 to 97500)
## Processing batch 196 of 407 (features 97501 to 98000)
## Processing batch 197 of 407 (features 98001 to 98500)
## Processing batch 198 of 407 (features 98501 to 99000)
## Processing batch 199 of 407 (features 99001 to 99500)
## Processing batch 200 of 407 (features 99501 to 100000)
## Processing batch 201 of 407 (features 100001 to 100500)
## Processing batch 202 of 407 (features 100501 to 101000)
## Processing batch 203 of 407 (features 101001 to 101500)
## Processing batch 204 of 407 (features 101501 to 102000)
## Processing batch 205 of 407 (features 102001 to 102500)
## Processing batch 206 of 407 (features 102501 to 103000)
## Processing batch 207 of 407 (features 103001 to 103500)
## Processing batch 208 of 407 (features 103501 to 104000)
## Processing batch 209 of 407 (features 104001 to 104500)
## Processing batch 210 of 407 (features 104501 to 105000)
## Processing batch 211 of 407 (features 105001 to 105500)
## Processing batch 212 of 407 (features 105501 to 106000)
## Processing batch 213 of 407 (features 106001 to 106500)
## Processing batch 214 of 407 (features 106501 to 107000)
## Processing batch 215 of 407 (features 107001 to 107500)
## Processing batch 216 of 407 (features 107501 to 108000)
## Processing batch 217 of 407 (features 108001 to 108500)
## Processing batch 218 of 407 (features 108501 to 109000)
## Processing batch 219 of 407 (features 109001 to 109500)
## Processing batch 220 of 407 (features 109501 to 110000)
## Processing batch 221 of 407 (features 110001 to 110500)
## Processing batch 222 of 407 (features 110501 to 111000)
## Processing batch 223 of 407 (features 111001 to 111500)
## Processing batch 224 of 407 (features 111501 to 112000)
## Processing batch 225 of 407 (features 112001 to 112500)
## Processing batch 226 of 407 (features 112501 to 113000)
## Processing batch 227 of 407 (features 113001 to 113500)
## Processing batch 228 of 407 (features 113501 to 114000)
## Processing batch 229 of 407 (features 114001 to 114500)
## Processing batch 230 of 407 (features 114501 to 115000)
## Processing batch 231 of 407 (features 115001 to 115500)
## Processing batch 232 of 407 (features 115501 to 116000)
## Processing batch 233 of 407 (features 116001 to 116500)
## Processing batch 234 of 407 (features 116501 to 117000)
## Processing batch 235 of 407 (features 117001 to 117500)
## Processing batch 236 of 407 (features 117501 to 118000)
## Processing batch 237 of 407 (features 118001 to 118500)
## Processing batch 238 of 407 (features 118501 to 119000)
## Processing batch 239 of 407 (features 119001 to 119500)
## Processing batch 240 of 407 (features 119501 to 120000)
## Processing batch 241 of 407 (features 120001 to 120500)
## Processing batch 242 of 407 (features 120501 to 121000)
## Processing batch 243 of 407 (features 121001 to 121500)
## Processing batch 244 of 407 (features 121501 to 122000)
## Processing batch 245 of 407 (features 122001 to 122500)
## Processing batch 246 of 407 (features 122501 to 123000)
## Processing batch 247 of 407 (features 123001 to 123500)
## Processing batch 248 of 407 (features 123501 to 124000)
## Processing batch 249 of 407 (features 124001 to 124500)
## Processing batch 250 of 407 (features 124501 to 125000)
## Processing batch 251 of 407 (features 125001 to 125500)
## Processing batch 252 of 407 (features 125501 to 126000)
## Processing batch 253 of 407 (features 126001 to 126500)
## Processing batch 254 of 407 (features 126501 to 127000)
## Processing batch 255 of 407 (features 127001 to 127500)
## Processing batch 256 of 407 (features 127501 to 128000)
## Processing batch 257 of 407 (features 128001 to 128500)
## Processing batch 258 of 407 (features 128501 to 129000)
## Processing batch 259 of 407 (features 129001 to 129500)
## Processing batch 260 of 407 (features 129501 to 130000)
## Processing batch 261 of 407 (features 130001 to 130500)
## Processing batch 262 of 407 (features 130501 to 131000)
## Processing batch 263 of 407 (features 131001 to 131500)
## Processing batch 264 of 407 (features 131501 to 132000)
## Processing batch 265 of 407 (features 132001 to 132500)
## Processing batch 266 of 407 (features 132501 to 133000)
## Processing batch 267 of 407 (features 133001 to 133500)
## Processing batch 268 of 407 (features 133501 to 134000)
## Processing batch 269 of 407 (features 134001 to 134500)
## Processing batch 270 of 407 (features 134501 to 135000)
## Processing batch 271 of 407 (features 135001 to 135500)
## Processing batch 272 of 407 (features 135501 to 136000)
## Processing batch 273 of 407 (features 136001 to 136500)
## Processing batch 274 of 407 (features 136501 to 137000)
## Processing batch 275 of 407 (features 137001 to 137500)
## Processing batch 276 of 407 (features 137501 to 138000)
## Processing batch 277 of 407 (features 138001 to 138500)
## Processing batch 278 of 407 (features 138501 to 139000)
## Processing batch 279 of 407 (features 139001 to 139500)
## Processing batch 280 of 407 (features 139501 to 140000)
## Processing batch 281 of 407 (features 140001 to 140500)
## Processing batch 282 of 407 (features 140501 to 141000)
## Processing batch 283 of 407 (features 141001 to 141500)
## Processing batch 284 of 407 (features 141501 to 142000)
## Processing batch 285 of 407 (features 142001 to 142500)
## Processing batch 286 of 407 (features 142501 to 143000)
## Processing batch 287 of 407 (features 143001 to 143500)
## Processing batch 288 of 407 (features 143501 to 144000)
## Processing batch 289 of 407 (features 144001 to 144500)
## Processing batch 290 of 407 (features 144501 to 145000)
## Processing batch 291 of 407 (features 145001 to 145500)
## Processing batch 292 of 407 (features 145501 to 146000)
## Processing batch 293 of 407 (features 146001 to 146500)
## Processing batch 294 of 407 (features 146501 to 147000)
## Processing batch 295 of 407 (features 147001 to 147500)
## Processing batch 296 of 407 (features 147501 to 148000)
## Processing batch 297 of 407 (features 148001 to 148500)
## Processing batch 298 of 407 (features 148501 to 149000)
## Processing batch 299 of 407 (features 149001 to 149500)
## Processing batch 300 of 407 (features 149501 to 150000)
## Processing batch 301 of 407 (features 150001 to 150500)
## Processing batch 302 of 407 (features 150501 to 151000)
## Processing batch 303 of 407 (features 151001 to 151500)
## Processing batch 304 of 407 (features 151501 to 152000)
## Processing batch 305 of 407 (features 152001 to 152500)
## Processing batch 306 of 407 (features 152501 to 153000)
## Processing batch 307 of 407 (features 153001 to 153500)
## Processing batch 308 of 407 (features 153501 to 154000)
## Processing batch 309 of 407 (features 154001 to 154500)
## Processing batch 310 of 407 (features 154501 to 155000)
## Processing batch 311 of 407 (features 155001 to 155500)
## Processing batch 312 of 407 (features 155501 to 156000)
## Processing batch 313 of 407 (features 156001 to 156500)
## Processing batch 314 of 407 (features 156501 to 157000)
## Processing batch 315 of 407 (features 157001 to 157500)
## Processing batch 316 of 407 (features 157501 to 158000)
## Processing batch 317 of 407 (features 158001 to 158500)
## Processing batch 318 of 407 (features 158501 to 159000)
## Processing batch 319 of 407 (features 159001 to 159500)
## Processing batch 320 of 407 (features 159501 to 160000)
## Processing batch 321 of 407 (features 160001 to 160500)
## Processing batch 322 of 407 (features 160501 to 161000)
## Processing batch 323 of 407 (features 161001 to 161500)
## Processing batch 324 of 407 (features 161501 to 162000)
## Processing batch 325 of 407 (features 162001 to 162500)
## Processing batch 326 of 407 (features 162501 to 163000)
## Processing batch 327 of 407 (features 163001 to 163500)
## Processing batch 328 of 407 (features 163501 to 164000)
## Processing batch 329 of 407 (features 164001 to 164500)
## Processing batch 330 of 407 (features 164501 to 165000)
## Processing batch 331 of 407 (features 165001 to 165500)
## Processing batch 332 of 407 (features 165501 to 166000)
## Processing batch 333 of 407 (features 166001 to 166500)
## Processing batch 334 of 407 (features 166501 to 167000)
## Processing batch 335 of 407 (features 167001 to 167500)
## Processing batch 336 of 407 (features 167501 to 168000)
## Processing batch 337 of 407 (features 168001 to 168500)
## Processing batch 338 of 407 (features 168501 to 169000)
## Processing batch 339 of 407 (features 169001 to 169500)
## Processing batch 340 of 407 (features 169501 to 170000)
## Processing batch 341 of 407 (features 170001 to 170500)
## Processing batch 342 of 407 (features 170501 to 171000)
## Processing batch 343 of 407 (features 171001 to 171500)
## Processing batch 344 of 407 (features 171501 to 172000)
## Processing batch 345 of 407 (features 172001 to 172500)
## Processing batch 346 of 407 (features 172501 to 173000)
## Processing batch 347 of 407 (features 173001 to 173500)
## Processing batch 348 of 407 (features 173501 to 174000)
## Processing batch 349 of 407 (features 174001 to 174500)
## Processing batch 350 of 407 (features 174501 to 175000)
## Processing batch 351 of 407 (features 175001 to 175500)
## Processing batch 352 of 407 (features 175501 to 176000)
## Processing batch 353 of 407 (features 176001 to 176500)
## Processing batch 354 of 407 (features 176501 to 177000)
## Processing batch 355 of 407 (features 177001 to 177500)
## Processing batch 356 of 407 (features 177501 to 178000)
## Processing batch 357 of 407 (features 178001 to 178500)
## Processing batch 358 of 407 (features 178501 to 179000)
## Processing batch 359 of 407 (features 179001 to 179500)
## Processing batch 360 of 407 (features 179501 to 180000)
## Processing batch 361 of 407 (features 180001 to 180500)
## Processing batch 362 of 407 (features 180501 to 181000)
## Processing batch 363 of 407 (features 181001 to 181500)
## Processing batch 364 of 407 (features 181501 to 182000)
## Processing batch 365 of 407 (features 182001 to 182500)
## Processing batch 366 of 407 (features 182501 to 183000)
## Processing batch 367 of 407 (features 183001 to 183500)
## Processing batch 368 of 407 (features 183501 to 184000)
## Processing batch 369 of 407 (features 184001 to 184500)
## Processing batch 370 of 407 (features 184501 to 185000)
## Processing batch 371 of 407 (features 185001 to 185500)
## Processing batch 372 of 407 (features 185501 to 186000)
## Processing batch 373 of 407 (features 186001 to 186500)
## Processing batch 374 of 407 (features 186501 to 187000)
## Processing batch 375 of 407 (features 187001 to 187500)
## Processing batch 376 of 407 (features 187501 to 188000)
## Processing batch 377 of 407 (features 188001 to 188500)
## Processing batch 378 of 407 (features 188501 to 189000)
## Processing batch 379 of 407 (features 189001 to 189500)
## Processing batch 380 of 407 (features 189501 to 190000)
## Processing batch 381 of 407 (features 190001 to 190500)
## Processing batch 382 of 407 (features 190501 to 191000)
## Processing batch 383 of 407 (features 191001 to 191500)
## Processing batch 384 of 407 (features 191501 to 192000)
## Processing batch 385 of 407 (features 192001 to 192500)
## Processing batch 386 of 407 (features 192501 to 193000)
## Processing batch 387 of 407 (features 193001 to 193500)
## Processing batch 388 of 407 (features 193501 to 194000)
## Processing batch 389 of 407 (features 194001 to 194500)
## Processing batch 390 of 407 (features 194501 to 195000)
## Processing batch 391 of 407 (features 195001 to 195500)
## Processing batch 392 of 407 (features 195501 to 196000)
## Processing batch 393 of 407 (features 196001 to 196500)
## Processing batch 394 of 407 (features 196501 to 197000)
## Processing batch 395 of 407 (features 197001 to 197500)
## Processing batch 396 of 407 (features 197501 to 198000)
## Processing batch 397 of 407 (features 198001 to 198500)
## Processing batch 398 of 407 (features 198501 to 199000)
## Processing batch 399 of 407 (features 199001 to 199500)
## Processing batch 400 of 407 (features 199501 to 200000)
## Processing batch 401 of 407 (features 200001 to 200500)
## Processing batch 402 of 407 (features 200501 to 201000)
## Processing batch 403 of 407 (features 201001 to 201500)
## Processing batch 404 of 407 (features 201501 to 202000)
## Processing batch 405 of 407 (features 202001 to 202500)
## Processing batch 406 of 407 (features 202501 to 203000)
## Processing batch 407 of 407 (features 203001 to 203015)
## Reprojecting results back to original CRS...
cat("Creating construction line buffers...\n")
## Creating construction line buffers...
# Calculate segment length in meters
df.const.lines_with_length <- df.const.lines %>%
# Transform to meter-based CRS
st_transform(3310) %>%
# Calculate length in meters
mutate(segment_length_m = as.numeric(st_length(geometry))) %>%
# Transform back to WGS84
st_transform(4326)
# Step 1A-L: Create construction line buffers
construction_line_buffers <- df.const.lines_with_length %>%
# Add ID as a primary key if it doesn't exist
mutate(construction_id = if("ID" %in% names(.)) ID else row_number()) %>%
# Select only needed columns
select(construction_id, Start_Time, End_Time, segment_length_m, geometry) %>%
# Rename columns to match our schema
rename(start_time = Start_Time, end_time = End_Time) %>%
# Create the buffer using our batch function
create_buffers_in_batches(buffer_dist = 300, batch_size = 250)
## Reprojecting data to a meter-based CRS...
## Processing batch 1 of 693 (features 1 to 250)
## Processing batch 2 of 693 (features 251 to 500)
## Processing batch 3 of 693 (features 501 to 750)
## Processing batch 4 of 693 (features 751 to 1000)
## Processing batch 5 of 693 (features 1001 to 1250)
## Processing batch 6 of 693 (features 1251 to 1500)
## Processing batch 7 of 693 (features 1501 to 1750)
## Processing batch 8 of 693 (features 1751 to 2000)
## Processing batch 9 of 693 (features 2001 to 2250)
## Processing batch 10 of 693 (features 2251 to 2500)
## Processing batch 11 of 693 (features 2501 to 2750)
## Processing batch 12 of 693 (features 2751 to 3000)
## Processing batch 13 of 693 (features 3001 to 3250)
## Processing batch 14 of 693 (features 3251 to 3500)
## Processing batch 15 of 693 (features 3501 to 3750)
## Processing batch 16 of 693 (features 3751 to 4000)
## Processing batch 17 of 693 (features 4001 to 4250)
## Processing batch 18 of 693 (features 4251 to 4500)
## Processing batch 19 of 693 (features 4501 to 4750)
## Processing batch 20 of 693 (features 4751 to 5000)
## Processing batch 21 of 693 (features 5001 to 5250)
## Processing batch 22 of 693 (features 5251 to 5500)
## Processing batch 23 of 693 (features 5501 to 5750)
## Processing batch 24 of 693 (features 5751 to 6000)
## Processing batch 25 of 693 (features 6001 to 6250)
## Processing batch 26 of 693 (features 6251 to 6500)
## Processing batch 27 of 693 (features 6501 to 6750)
## Processing batch 28 of 693 (features 6751 to 7000)
## Processing batch 29 of 693 (features 7001 to 7250)
## Processing batch 30 of 693 (features 7251 to 7500)
## Processing batch 31 of 693 (features 7501 to 7750)
## Processing batch 32 of 693 (features 7751 to 8000)
## Processing batch 33 of 693 (features 8001 to 8250)
## Processing batch 34 of 693 (features 8251 to 8500)
## Processing batch 35 of 693 (features 8501 to 8750)
## Processing batch 36 of 693 (features 8751 to 9000)
## Processing batch 37 of 693 (features 9001 to 9250)
## Processing batch 38 of 693 (features 9251 to 9500)
## Processing batch 39 of 693 (features 9501 to 9750)
## Processing batch 40 of 693 (features 9751 to 10000)
## Processing batch 41 of 693 (features 10001 to 10250)
## Processing batch 42 of 693 (features 10251 to 10500)
## Processing batch 43 of 693 (features 10501 to 10750)
## Processing batch 44 of 693 (features 10751 to 11000)
## Processing batch 45 of 693 (features 11001 to 11250)
## Processing batch 46 of 693 (features 11251 to 11500)
## Processing batch 47 of 693 (features 11501 to 11750)
## Processing batch 48 of 693 (features 11751 to 12000)
## Processing batch 49 of 693 (features 12001 to 12250)
## Processing batch 50 of 693 (features 12251 to 12500)
## Processing batch 51 of 693 (features 12501 to 12750)
## Processing batch 52 of 693 (features 12751 to 13000)
## Processing batch 53 of 693 (features 13001 to 13250)
## Processing batch 54 of 693 (features 13251 to 13500)
## Processing batch 55 of 693 (features 13501 to 13750)
## Processing batch 56 of 693 (features 13751 to 14000)
## Processing batch 57 of 693 (features 14001 to 14250)
## Processing batch 58 of 693 (features 14251 to 14500)
## Processing batch 59 of 693 (features 14501 to 14750)
## Processing batch 60 of 693 (features 14751 to 15000)
## Processing batch 61 of 693 (features 15001 to 15250)
## Processing batch 62 of 693 (features 15251 to 15500)
## Processing batch 63 of 693 (features 15501 to 15750)
## Processing batch 64 of 693 (features 15751 to 16000)
## Processing batch 65 of 693 (features 16001 to 16250)
## Processing batch 66 of 693 (features 16251 to 16500)
## Processing batch 67 of 693 (features 16501 to 16750)
## Processing batch 68 of 693 (features 16751 to 17000)
## Processing batch 69 of 693 (features 17001 to 17250)
## Processing batch 70 of 693 (features 17251 to 17500)
## Processing batch 71 of 693 (features 17501 to 17750)
## Processing batch 72 of 693 (features 17751 to 18000)
## Processing batch 73 of 693 (features 18001 to 18250)
## Processing batch 74 of 693 (features 18251 to 18500)
## Processing batch 75 of 693 (features 18501 to 18750)
## Processing batch 76 of 693 (features 18751 to 19000)
## Processing batch 77 of 693 (features 19001 to 19250)
## Processing batch 78 of 693 (features 19251 to 19500)
## Processing batch 79 of 693 (features 19501 to 19750)
## Processing batch 80 of 693 (features 19751 to 20000)
## Processing batch 81 of 693 (features 20001 to 20250)
## Processing batch 82 of 693 (features 20251 to 20500)
## Processing batch 83 of 693 (features 20501 to 20750)
## Processing batch 84 of 693 (features 20751 to 21000)
## Processing batch 85 of 693 (features 21001 to 21250)
## Processing batch 86 of 693 (features 21251 to 21500)
## Processing batch 87 of 693 (features 21501 to 21750)
## Processing batch 88 of 693 (features 21751 to 22000)
## Processing batch 89 of 693 (features 22001 to 22250)
## Processing batch 90 of 693 (features 22251 to 22500)
## Processing batch 91 of 693 (features 22501 to 22750)
## Processing batch 92 of 693 (features 22751 to 23000)
## Processing batch 93 of 693 (features 23001 to 23250)
## Processing batch 94 of 693 (features 23251 to 23500)
## Processing batch 95 of 693 (features 23501 to 23750)
## Processing batch 96 of 693 (features 23751 to 24000)
## Processing batch 97 of 693 (features 24001 to 24250)
## Processing batch 98 of 693 (features 24251 to 24500)
## Processing batch 99 of 693 (features 24501 to 24750)
## Processing batch 100 of 693 (features 24751 to 25000)
## Processing batch 101 of 693 (features 25001 to 25250)
## Processing batch 102 of 693 (features 25251 to 25500)
## Processing batch 103 of 693 (features 25501 to 25750)
## Processing batch 104 of 693 (features 25751 to 26000)
## Processing batch 105 of 693 (features 26001 to 26250)
## Processing batch 106 of 693 (features 26251 to 26500)
## Processing batch 107 of 693 (features 26501 to 26750)
## Processing batch 108 of 693 (features 26751 to 27000)
## Processing batch 109 of 693 (features 27001 to 27250)
## Processing batch 110 of 693 (features 27251 to 27500)
## Processing batch 111 of 693 (features 27501 to 27750)
## Processing batch 112 of 693 (features 27751 to 28000)
## Processing batch 113 of 693 (features 28001 to 28250)
## Processing batch 114 of 693 (features 28251 to 28500)
## Processing batch 115 of 693 (features 28501 to 28750)
## Processing batch 116 of 693 (features 28751 to 29000)
## Processing batch 117 of 693 (features 29001 to 29250)
## Processing batch 118 of 693 (features 29251 to 29500)
## Processing batch 119 of 693 (features 29501 to 29750)
## Processing batch 120 of 693 (features 29751 to 30000)
## Processing batch 121 of 693 (features 30001 to 30250)
## Processing batch 122 of 693 (features 30251 to 30500)
## Processing batch 123 of 693 (features 30501 to 30750)
## Processing batch 124 of 693 (features 30751 to 31000)
## Processing batch 125 of 693 (features 31001 to 31250)
## Processing batch 126 of 693 (features 31251 to 31500)
## Processing batch 127 of 693 (features 31501 to 31750)
## Processing batch 128 of 693 (features 31751 to 32000)
## Processing batch 129 of 693 (features 32001 to 32250)
## Processing batch 130 of 693 (features 32251 to 32500)
## Processing batch 131 of 693 (features 32501 to 32750)
## Processing batch 132 of 693 (features 32751 to 33000)
## Processing batch 133 of 693 (features 33001 to 33250)
## Processing batch 134 of 693 (features 33251 to 33500)
## Processing batch 135 of 693 (features 33501 to 33750)
## Processing batch 136 of 693 (features 33751 to 34000)
## Processing batch 137 of 693 (features 34001 to 34250)
## Processing batch 138 of 693 (features 34251 to 34500)
## Processing batch 139 of 693 (features 34501 to 34750)
## Processing batch 140 of 693 (features 34751 to 35000)
## Processing batch 141 of 693 (features 35001 to 35250)
## Processing batch 142 of 693 (features 35251 to 35500)
## Processing batch 143 of 693 (features 35501 to 35750)
## Processing batch 144 of 693 (features 35751 to 36000)
## Processing batch 145 of 693 (features 36001 to 36250)
## Processing batch 146 of 693 (features 36251 to 36500)
## Processing batch 147 of 693 (features 36501 to 36750)
## Processing batch 148 of 693 (features 36751 to 37000)
## Processing batch 149 of 693 (features 37001 to 37250)
## Processing batch 150 of 693 (features 37251 to 37500)
## Processing batch 151 of 693 (features 37501 to 37750)
## Processing batch 152 of 693 (features 37751 to 38000)
## Processing batch 153 of 693 (features 38001 to 38250)
## Processing batch 154 of 693 (features 38251 to 38500)
## Processing batch 155 of 693 (features 38501 to 38750)
## Processing batch 156 of 693 (features 38751 to 39000)
## Processing batch 157 of 693 (features 39001 to 39250)
## Processing batch 158 of 693 (features 39251 to 39500)
## Processing batch 159 of 693 (features 39501 to 39750)
## Processing batch 160 of 693 (features 39751 to 40000)
## Processing batch 161 of 693 (features 40001 to 40250)
## Processing batch 162 of 693 (features 40251 to 40500)
## Processing batch 163 of 693 (features 40501 to 40750)
## Processing batch 164 of 693 (features 40751 to 41000)
## Processing batch 165 of 693 (features 41001 to 41250)
## Processing batch 166 of 693 (features 41251 to 41500)
## Processing batch 167 of 693 (features 41501 to 41750)
## Processing batch 168 of 693 (features 41751 to 42000)
## Processing batch 169 of 693 (features 42001 to 42250)
## Processing batch 170 of 693 (features 42251 to 42500)
## Processing batch 171 of 693 (features 42501 to 42750)
## Processing batch 172 of 693 (features 42751 to 43000)
## Processing batch 173 of 693 (features 43001 to 43250)
## Processing batch 174 of 693 (features 43251 to 43500)
## Processing batch 175 of 693 (features 43501 to 43750)
## Processing batch 176 of 693 (features 43751 to 44000)
## Processing batch 177 of 693 (features 44001 to 44250)
## Processing batch 178 of 693 (features 44251 to 44500)
## Processing batch 179 of 693 (features 44501 to 44750)
## Processing batch 180 of 693 (features 44751 to 45000)
## Processing batch 181 of 693 (features 45001 to 45250)
## Processing batch 182 of 693 (features 45251 to 45500)
## Processing batch 183 of 693 (features 45501 to 45750)
## Processing batch 184 of 693 (features 45751 to 46000)
## Processing batch 185 of 693 (features 46001 to 46250)
## Processing batch 186 of 693 (features 46251 to 46500)
## Processing batch 187 of 693 (features 46501 to 46750)
## Processing batch 188 of 693 (features 46751 to 47000)
## Processing batch 189 of 693 (features 47001 to 47250)
## Processing batch 190 of 693 (features 47251 to 47500)
## Processing batch 191 of 693 (features 47501 to 47750)
## Processing batch 192 of 693 (features 47751 to 48000)
## Processing batch 193 of 693 (features 48001 to 48250)
## Processing batch 194 of 693 (features 48251 to 48500)
## Processing batch 195 of 693 (features 48501 to 48750)
## Processing batch 196 of 693 (features 48751 to 49000)
## Processing batch 197 of 693 (features 49001 to 49250)
## Processing batch 198 of 693 (features 49251 to 49500)
## Processing batch 199 of 693 (features 49501 to 49750)
## Processing batch 200 of 693 (features 49751 to 50000)
## Processing batch 201 of 693 (features 50001 to 50250)
## Processing batch 202 of 693 (features 50251 to 50500)
## Processing batch 203 of 693 (features 50501 to 50750)
## Processing batch 204 of 693 (features 50751 to 51000)
## Processing batch 205 of 693 (features 51001 to 51250)
## Processing batch 206 of 693 (features 51251 to 51500)
## Processing batch 207 of 693 (features 51501 to 51750)
## Processing batch 208 of 693 (features 51751 to 52000)
## Processing batch 209 of 693 (features 52001 to 52250)
## Processing batch 210 of 693 (features 52251 to 52500)
## Processing batch 211 of 693 (features 52501 to 52750)
## Processing batch 212 of 693 (features 52751 to 53000)
## Processing batch 213 of 693 (features 53001 to 53250)
## Processing batch 214 of 693 (features 53251 to 53500)
## Processing batch 215 of 693 (features 53501 to 53750)
## Processing batch 216 of 693 (features 53751 to 54000)
## Processing batch 217 of 693 (features 54001 to 54250)
## Processing batch 218 of 693 (features 54251 to 54500)
## Processing batch 219 of 693 (features 54501 to 54750)
## Processing batch 220 of 693 (features 54751 to 55000)
## Processing batch 221 of 693 (features 55001 to 55250)
## Processing batch 222 of 693 (features 55251 to 55500)
## Processing batch 223 of 693 (features 55501 to 55750)
## Processing batch 224 of 693 (features 55751 to 56000)
## Processing batch 225 of 693 (features 56001 to 56250)
## Processing batch 226 of 693 (features 56251 to 56500)
## Processing batch 227 of 693 (features 56501 to 56750)
## Processing batch 228 of 693 (features 56751 to 57000)
## Processing batch 229 of 693 (features 57001 to 57250)
## Processing batch 230 of 693 (features 57251 to 57500)
## Processing batch 231 of 693 (features 57501 to 57750)
## Processing batch 232 of 693 (features 57751 to 58000)
## Processing batch 233 of 693 (features 58001 to 58250)
## Processing batch 234 of 693 (features 58251 to 58500)
## Processing batch 235 of 693 (features 58501 to 58750)
## Processing batch 236 of 693 (features 58751 to 59000)
## Processing batch 237 of 693 (features 59001 to 59250)
## Processing batch 238 of 693 (features 59251 to 59500)
## Processing batch 239 of 693 (features 59501 to 59750)
## Processing batch 240 of 693 (features 59751 to 60000)
## Processing batch 241 of 693 (features 60001 to 60250)
## Processing batch 242 of 693 (features 60251 to 60500)
## Processing batch 243 of 693 (features 60501 to 60750)
## Processing batch 244 of 693 (features 60751 to 61000)
## Processing batch 245 of 693 (features 61001 to 61250)
## Processing batch 246 of 693 (features 61251 to 61500)
## Processing batch 247 of 693 (features 61501 to 61750)
## Processing batch 248 of 693 (features 61751 to 62000)
## Processing batch 249 of 693 (features 62001 to 62250)
## Processing batch 250 of 693 (features 62251 to 62500)
## Processing batch 251 of 693 (features 62501 to 62750)
## Processing batch 252 of 693 (features 62751 to 63000)
## Processing batch 253 of 693 (features 63001 to 63250)
## Processing batch 254 of 693 (features 63251 to 63500)
## Processing batch 255 of 693 (features 63501 to 63750)
## Processing batch 256 of 693 (features 63751 to 64000)
## Processing batch 257 of 693 (features 64001 to 64250)
## Processing batch 258 of 693 (features 64251 to 64500)
## Processing batch 259 of 693 (features 64501 to 64750)
## Processing batch 260 of 693 (features 64751 to 65000)
## Processing batch 261 of 693 (features 65001 to 65250)
## Processing batch 262 of 693 (features 65251 to 65500)
## Processing batch 263 of 693 (features 65501 to 65750)
## Processing batch 264 of 693 (features 65751 to 66000)
## Processing batch 265 of 693 (features 66001 to 66250)
## Processing batch 266 of 693 (features 66251 to 66500)
## Processing batch 267 of 693 (features 66501 to 66750)
## Processing batch 268 of 693 (features 66751 to 67000)
## Processing batch 269 of 693 (features 67001 to 67250)
## Processing batch 270 of 693 (features 67251 to 67500)
## Processing batch 271 of 693 (features 67501 to 67750)
## Processing batch 272 of 693 (features 67751 to 68000)
## Processing batch 273 of 693 (features 68001 to 68250)
## Processing batch 274 of 693 (features 68251 to 68500)
## Processing batch 275 of 693 (features 68501 to 68750)
## Processing batch 276 of 693 (features 68751 to 69000)
## Processing batch 277 of 693 (features 69001 to 69250)
## Processing batch 278 of 693 (features 69251 to 69500)
## Processing batch 279 of 693 (features 69501 to 69750)
## Processing batch 280 of 693 (features 69751 to 70000)
## Processing batch 281 of 693 (features 70001 to 70250)
## Processing batch 282 of 693 (features 70251 to 70500)
## Processing batch 283 of 693 (features 70501 to 70750)
## Processing batch 284 of 693 (features 70751 to 71000)
## Processing batch 285 of 693 (features 71001 to 71250)
## Processing batch 286 of 693 (features 71251 to 71500)
## Processing batch 287 of 693 (features 71501 to 71750)
## Processing batch 288 of 693 (features 71751 to 72000)
## Processing batch 289 of 693 (features 72001 to 72250)
## Processing batch 290 of 693 (features 72251 to 72500)
## Processing batch 291 of 693 (features 72501 to 72750)
## Processing batch 292 of 693 (features 72751 to 73000)
## Processing batch 293 of 693 (features 73001 to 73250)
## Processing batch 294 of 693 (features 73251 to 73500)
## Processing batch 295 of 693 (features 73501 to 73750)
## Processing batch 296 of 693 (features 73751 to 74000)
## Processing batch 297 of 693 (features 74001 to 74250)
## Processing batch 298 of 693 (features 74251 to 74500)
## Processing batch 299 of 693 (features 74501 to 74750)
## Processing batch 300 of 693 (features 74751 to 75000)
## Processing batch 301 of 693 (features 75001 to 75250)
## Processing batch 302 of 693 (features 75251 to 75500)
## Processing batch 303 of 693 (features 75501 to 75750)
## Processing batch 304 of 693 (features 75751 to 76000)
## Processing batch 305 of 693 (features 76001 to 76250)
## Processing batch 306 of 693 (features 76251 to 76500)
## Processing batch 307 of 693 (features 76501 to 76750)
## Processing batch 308 of 693 (features 76751 to 77000)
## Processing batch 309 of 693 (features 77001 to 77250)
## Processing batch 310 of 693 (features 77251 to 77500)
## Processing batch 311 of 693 (features 77501 to 77750)
## Processing batch 312 of 693 (features 77751 to 78000)
## Processing batch 313 of 693 (features 78001 to 78250)
## Processing batch 314 of 693 (features 78251 to 78500)
## Processing batch 315 of 693 (features 78501 to 78750)
## Processing batch 316 of 693 (features 78751 to 79000)
## Processing batch 317 of 693 (features 79001 to 79250)
## Processing batch 318 of 693 (features 79251 to 79500)
## Processing batch 319 of 693 (features 79501 to 79750)
## Processing batch 320 of 693 (features 79751 to 80000)
## Processing batch 321 of 693 (features 80001 to 80250)
## Processing batch 322 of 693 (features 80251 to 80500)
## Processing batch 323 of 693 (features 80501 to 80750)
## Processing batch 324 of 693 (features 80751 to 81000)
## Processing batch 325 of 693 (features 81001 to 81250)
## Processing batch 326 of 693 (features 81251 to 81500)
## Processing batch 327 of 693 (features 81501 to 81750)
## Processing batch 328 of 693 (features 81751 to 82000)
## Processing batch 329 of 693 (features 82001 to 82250)
## Processing batch 330 of 693 (features 82251 to 82500)
## Processing batch 331 of 693 (features 82501 to 82750)
## Processing batch 332 of 693 (features 82751 to 83000)
## Processing batch 333 of 693 (features 83001 to 83250)
## Processing batch 334 of 693 (features 83251 to 83500)
## Processing batch 335 of 693 (features 83501 to 83750)
## Processing batch 336 of 693 (features 83751 to 84000)
## Processing batch 337 of 693 (features 84001 to 84250)
## Processing batch 338 of 693 (features 84251 to 84500)
## Processing batch 339 of 693 (features 84501 to 84750)
## Processing batch 340 of 693 (features 84751 to 85000)
## Processing batch 341 of 693 (features 85001 to 85250)
## Processing batch 342 of 693 (features 85251 to 85500)
## Processing batch 343 of 693 (features 85501 to 85750)
## Processing batch 344 of 693 (features 85751 to 86000)
## Processing batch 345 of 693 (features 86001 to 86250)
## Processing batch 346 of 693 (features 86251 to 86500)
## Processing batch 347 of 693 (features 86501 to 86750)
## Processing batch 348 of 693 (features 86751 to 87000)
## Processing batch 349 of 693 (features 87001 to 87250)
## Processing batch 350 of 693 (features 87251 to 87500)
## Processing batch 351 of 693 (features 87501 to 87750)
## Processing batch 352 of 693 (features 87751 to 88000)
## Processing batch 353 of 693 (features 88001 to 88250)
## Processing batch 354 of 693 (features 88251 to 88500)
## Processing batch 355 of 693 (features 88501 to 88750)
## Processing batch 356 of 693 (features 88751 to 89000)
## Processing batch 357 of 693 (features 89001 to 89250)
## Processing batch 358 of 693 (features 89251 to 89500)
## Processing batch 359 of 693 (features 89501 to 89750)
## Processing batch 360 of 693 (features 89751 to 90000)
## Processing batch 361 of 693 (features 90001 to 90250)
## Processing batch 362 of 693 (features 90251 to 90500)
## Processing batch 363 of 693 (features 90501 to 90750)
## Processing batch 364 of 693 (features 90751 to 91000)
## Processing batch 365 of 693 (features 91001 to 91250)
## Processing batch 366 of 693 (features 91251 to 91500)
## Processing batch 367 of 693 (features 91501 to 91750)
## Processing batch 368 of 693 (features 91751 to 92000)
## Processing batch 369 of 693 (features 92001 to 92250)
## Processing batch 370 of 693 (features 92251 to 92500)
## Processing batch 371 of 693 (features 92501 to 92750)
## Processing batch 372 of 693 (features 92751 to 93000)
## Processing batch 373 of 693 (features 93001 to 93250)
## Processing batch 374 of 693 (features 93251 to 93500)
## Processing batch 375 of 693 (features 93501 to 93750)
## Processing batch 376 of 693 (features 93751 to 94000)
## Processing batch 377 of 693 (features 94001 to 94250)
## Processing batch 378 of 693 (features 94251 to 94500)
## Processing batch 379 of 693 (features 94501 to 94750)
## Processing batch 380 of 693 (features 94751 to 95000)
## Processing batch 381 of 693 (features 95001 to 95250)
## Processing batch 382 of 693 (features 95251 to 95500)
## Processing batch 383 of 693 (features 95501 to 95750)
## Processing batch 384 of 693 (features 95751 to 96000)
## Processing batch 385 of 693 (features 96001 to 96250)
## Processing batch 386 of 693 (features 96251 to 96500)
## Processing batch 387 of 693 (features 96501 to 96750)
## Processing batch 388 of 693 (features 96751 to 97000)
## Processing batch 389 of 693 (features 97001 to 97250)
## Processing batch 390 of 693 (features 97251 to 97500)
## Processing batch 391 of 693 (features 97501 to 97750)
## Processing batch 392 of 693 (features 97751 to 98000)
## Processing batch 393 of 693 (features 98001 to 98250)
## Processing batch 394 of 693 (features 98251 to 98500)
## Processing batch 395 of 693 (features 98501 to 98750)
## Processing batch 396 of 693 (features 98751 to 99000)
## Processing batch 397 of 693 (features 99001 to 99250)
## Processing batch 398 of 693 (features 99251 to 99500)
## Processing batch 399 of 693 (features 99501 to 99750)
## Processing batch 400 of 693 (features 99751 to 100000)
## Processing batch 401 of 693 (features 100001 to 100250)
## Processing batch 402 of 693 (features 100251 to 100500)
## Processing batch 403 of 693 (features 100501 to 100750)
## Processing batch 404 of 693 (features 100751 to 101000)
## Processing batch 405 of 693 (features 101001 to 101250)
## Processing batch 406 of 693 (features 101251 to 101500)
## Processing batch 407 of 693 (features 101501 to 101750)
## Processing batch 408 of 693 (features 101751 to 102000)
## Processing batch 409 of 693 (features 102001 to 102250)
## Processing batch 410 of 693 (features 102251 to 102500)
## Processing batch 411 of 693 (features 102501 to 102750)
## Processing batch 412 of 693 (features 102751 to 103000)
## Processing batch 413 of 693 (features 103001 to 103250)
## Processing batch 414 of 693 (features 103251 to 103500)
## Processing batch 415 of 693 (features 103501 to 103750)
## Processing batch 416 of 693 (features 103751 to 104000)
## Processing batch 417 of 693 (features 104001 to 104250)
## Processing batch 418 of 693 (features 104251 to 104500)
## Processing batch 419 of 693 (features 104501 to 104750)
## Processing batch 420 of 693 (features 104751 to 105000)
## Processing batch 421 of 693 (features 105001 to 105250)
## Processing batch 422 of 693 (features 105251 to 105500)
## Processing batch 423 of 693 (features 105501 to 105750)
## Processing batch 424 of 693 (features 105751 to 106000)
## Processing batch 425 of 693 (features 106001 to 106250)
## Processing batch 426 of 693 (features 106251 to 106500)
## Processing batch 427 of 693 (features 106501 to 106750)
## Processing batch 428 of 693 (features 106751 to 107000)
## Processing batch 429 of 693 (features 107001 to 107250)
## Processing batch 430 of 693 (features 107251 to 107500)
## Processing batch 431 of 693 (features 107501 to 107750)
## Processing batch 432 of 693 (features 107751 to 108000)
## Processing batch 433 of 693 (features 108001 to 108250)
## Processing batch 434 of 693 (features 108251 to 108500)
## Processing batch 435 of 693 (features 108501 to 108750)
## Processing batch 436 of 693 (features 108751 to 109000)
## Processing batch 437 of 693 (features 109001 to 109250)
## Processing batch 438 of 693 (features 109251 to 109500)
## Processing batch 439 of 693 (features 109501 to 109750)
## Processing batch 440 of 693 (features 109751 to 110000)
## Processing batch 441 of 693 (features 110001 to 110250)
## Processing batch 442 of 693 (features 110251 to 110500)
## Processing batch 443 of 693 (features 110501 to 110750)
## Processing batch 444 of 693 (features 110751 to 111000)
## Processing batch 445 of 693 (features 111001 to 111250)
## Processing batch 446 of 693 (features 111251 to 111500)
## Processing batch 447 of 693 (features 111501 to 111750)
## Processing batch 448 of 693 (features 111751 to 112000)
## Processing batch 449 of 693 (features 112001 to 112250)
## Processing batch 450 of 693 (features 112251 to 112500)
## Processing batch 451 of 693 (features 112501 to 112750)
## Processing batch 452 of 693 (features 112751 to 113000)
## Processing batch 453 of 693 (features 113001 to 113250)
## Processing batch 454 of 693 (features 113251 to 113500)
## Processing batch 455 of 693 (features 113501 to 113750)
## Processing batch 456 of 693 (features 113751 to 114000)
## Processing batch 457 of 693 (features 114001 to 114250)
## Processing batch 458 of 693 (features 114251 to 114500)
## Processing batch 459 of 693 (features 114501 to 114750)
## Processing batch 460 of 693 (features 114751 to 115000)
## Processing batch 461 of 693 (features 115001 to 115250)
## Processing batch 462 of 693 (features 115251 to 115500)
## Processing batch 463 of 693 (features 115501 to 115750)
## Processing batch 464 of 693 (features 115751 to 116000)
## Processing batch 465 of 693 (features 116001 to 116250)
## Processing batch 466 of 693 (features 116251 to 116500)
## Processing batch 467 of 693 (features 116501 to 116750)
## Processing batch 468 of 693 (features 116751 to 117000)
## Processing batch 469 of 693 (features 117001 to 117250)
## Processing batch 470 of 693 (features 117251 to 117500)
## Processing batch 471 of 693 (features 117501 to 117750)
## Processing batch 472 of 693 (features 117751 to 118000)
## Processing batch 473 of 693 (features 118001 to 118250)
## Processing batch 474 of 693 (features 118251 to 118500)
## Processing batch 475 of 693 (features 118501 to 118750)
## Processing batch 476 of 693 (features 118751 to 119000)
## Processing batch 477 of 693 (features 119001 to 119250)
## Processing batch 478 of 693 (features 119251 to 119500)
## Processing batch 479 of 693 (features 119501 to 119750)
## Processing batch 480 of 693 (features 119751 to 120000)
## Processing batch 481 of 693 (features 120001 to 120250)
## Processing batch 482 of 693 (features 120251 to 120500)
## Processing batch 483 of 693 (features 120501 to 120750)
## Processing batch 484 of 693 (features 120751 to 121000)
## Processing batch 485 of 693 (features 121001 to 121250)
## Processing batch 486 of 693 (features 121251 to 121500)
## Processing batch 487 of 693 (features 121501 to 121750)
## Processing batch 488 of 693 (features 121751 to 122000)
## Processing batch 489 of 693 (features 122001 to 122250)
## Processing batch 490 of 693 (features 122251 to 122500)
## Processing batch 491 of 693 (features 122501 to 122750)
## Processing batch 492 of 693 (features 122751 to 123000)
## Processing batch 493 of 693 (features 123001 to 123250)
## Processing batch 494 of 693 (features 123251 to 123500)
## Processing batch 495 of 693 (features 123501 to 123750)
## Processing batch 496 of 693 (features 123751 to 124000)
## Processing batch 497 of 693 (features 124001 to 124250)
## Processing batch 498 of 693 (features 124251 to 124500)
## Processing batch 499 of 693 (features 124501 to 124750)
## Processing batch 500 of 693 (features 124751 to 125000)
## Processing batch 501 of 693 (features 125001 to 125250)
## Processing batch 502 of 693 (features 125251 to 125500)
## Processing batch 503 of 693 (features 125501 to 125750)
## Processing batch 504 of 693 (features 125751 to 126000)
## Processing batch 505 of 693 (features 126001 to 126250)
## Processing batch 506 of 693 (features 126251 to 126500)
## Processing batch 507 of 693 (features 126501 to 126750)
## Processing batch 508 of 693 (features 126751 to 127000)
## Processing batch 509 of 693 (features 127001 to 127250)
## Processing batch 510 of 693 (features 127251 to 127500)
## Processing batch 511 of 693 (features 127501 to 127750)
## Processing batch 512 of 693 (features 127751 to 128000)
## Processing batch 513 of 693 (features 128001 to 128250)
## Processing batch 514 of 693 (features 128251 to 128500)
## Processing batch 515 of 693 (features 128501 to 128750)
## Processing batch 516 of 693 (features 128751 to 129000)
## Processing batch 517 of 693 (features 129001 to 129250)
## Processing batch 518 of 693 (features 129251 to 129500)
## Processing batch 519 of 693 (features 129501 to 129750)
## Processing batch 520 of 693 (features 129751 to 130000)
## Processing batch 521 of 693 (features 130001 to 130250)
## Processing batch 522 of 693 (features 130251 to 130500)
## Processing batch 523 of 693 (features 130501 to 130750)
## Processing batch 524 of 693 (features 130751 to 131000)
## Processing batch 525 of 693 (features 131001 to 131250)
## Processing batch 526 of 693 (features 131251 to 131500)
## Processing batch 527 of 693 (features 131501 to 131750)
## Processing batch 528 of 693 (features 131751 to 132000)
## Processing batch 529 of 693 (features 132001 to 132250)
## Processing batch 530 of 693 (features 132251 to 132500)
## Processing batch 531 of 693 (features 132501 to 132750)
## Processing batch 532 of 693 (features 132751 to 133000)
## Processing batch 533 of 693 (features 133001 to 133250)
## Processing batch 534 of 693 (features 133251 to 133500)
## Processing batch 535 of 693 (features 133501 to 133750)
## Processing batch 536 of 693 (features 133751 to 134000)
## Processing batch 537 of 693 (features 134001 to 134250)
## Processing batch 538 of 693 (features 134251 to 134500)
## Processing batch 539 of 693 (features 134501 to 134750)
## Processing batch 540 of 693 (features 134751 to 135000)
## Processing batch 541 of 693 (features 135001 to 135250)
## Processing batch 542 of 693 (features 135251 to 135500)
## Processing batch 543 of 693 (features 135501 to 135750)
## Processing batch 544 of 693 (features 135751 to 136000)
## Processing batch 545 of 693 (features 136001 to 136250)
## Processing batch 546 of 693 (features 136251 to 136500)
## Processing batch 547 of 693 (features 136501 to 136750)
## Processing batch 548 of 693 (features 136751 to 137000)
## Processing batch 549 of 693 (features 137001 to 137250)
## Processing batch 550 of 693 (features 137251 to 137500)
## Processing batch 551 of 693 (features 137501 to 137750)
## Processing batch 552 of 693 (features 137751 to 138000)
## Processing batch 553 of 693 (features 138001 to 138250)
## Processing batch 554 of 693 (features 138251 to 138500)
## Processing batch 555 of 693 (features 138501 to 138750)
## Processing batch 556 of 693 (features 138751 to 139000)
## Processing batch 557 of 693 (features 139001 to 139250)
## Processing batch 558 of 693 (features 139251 to 139500)
## Processing batch 559 of 693 (features 139501 to 139750)
## Processing batch 560 of 693 (features 139751 to 140000)
## Processing batch 561 of 693 (features 140001 to 140250)
## Processing batch 562 of 693 (features 140251 to 140500)
## Processing batch 563 of 693 (features 140501 to 140750)
## Processing batch 564 of 693 (features 140751 to 141000)
## Processing batch 565 of 693 (features 141001 to 141250)
## Processing batch 566 of 693 (features 141251 to 141500)
## Processing batch 567 of 693 (features 141501 to 141750)
## Processing batch 568 of 693 (features 141751 to 142000)
## Processing batch 569 of 693 (features 142001 to 142250)
## Processing batch 570 of 693 (features 142251 to 142500)
## Processing batch 571 of 693 (features 142501 to 142750)
## Processing batch 572 of 693 (features 142751 to 143000)
## Processing batch 573 of 693 (features 143001 to 143250)
## Processing batch 574 of 693 (features 143251 to 143500)
## Processing batch 575 of 693 (features 143501 to 143750)
## Processing batch 576 of 693 (features 143751 to 144000)
## Processing batch 577 of 693 (features 144001 to 144250)
## Processing batch 578 of 693 (features 144251 to 144500)
## Processing batch 579 of 693 (features 144501 to 144750)
## Processing batch 580 of 693 (features 144751 to 145000)
## Processing batch 581 of 693 (features 145001 to 145250)
## Processing batch 582 of 693 (features 145251 to 145500)
## Processing batch 583 of 693 (features 145501 to 145750)
## Processing batch 584 of 693 (features 145751 to 146000)
## Processing batch 585 of 693 (features 146001 to 146250)
## Processing batch 586 of 693 (features 146251 to 146500)
## Processing batch 587 of 693 (features 146501 to 146750)
## Processing batch 588 of 693 (features 146751 to 147000)
## Processing batch 589 of 693 (features 147001 to 147250)
## Processing batch 590 of 693 (features 147251 to 147500)
## Processing batch 591 of 693 (features 147501 to 147750)
## Processing batch 592 of 693 (features 147751 to 148000)
## Processing batch 593 of 693 (features 148001 to 148250)
## Processing batch 594 of 693 (features 148251 to 148500)
## Processing batch 595 of 693 (features 148501 to 148750)
## Processing batch 596 of 693 (features 148751 to 149000)
## Processing batch 597 of 693 (features 149001 to 149250)
## Processing batch 598 of 693 (features 149251 to 149500)
## Processing batch 599 of 693 (features 149501 to 149750)
## Processing batch 600 of 693 (features 149751 to 150000)
## Processing batch 601 of 693 (features 150001 to 150250)
## Processing batch 602 of 693 (features 150251 to 150500)
## Processing batch 603 of 693 (features 150501 to 150750)
## Processing batch 604 of 693 (features 150751 to 151000)
## Processing batch 605 of 693 (features 151001 to 151250)
## Processing batch 606 of 693 (features 151251 to 151500)
## Processing batch 607 of 693 (features 151501 to 151750)
## Processing batch 608 of 693 (features 151751 to 152000)
## Processing batch 609 of 693 (features 152001 to 152250)
## Processing batch 610 of 693 (features 152251 to 152500)
## Processing batch 611 of 693 (features 152501 to 152750)
## Processing batch 612 of 693 (features 152751 to 153000)
## Processing batch 613 of 693 (features 153001 to 153250)
## Processing batch 614 of 693 (features 153251 to 153500)
## Processing batch 615 of 693 (features 153501 to 153750)
## Processing batch 616 of 693 (features 153751 to 154000)
## Processing batch 617 of 693 (features 154001 to 154250)
## Processing batch 618 of 693 (features 154251 to 154500)
## Processing batch 619 of 693 (features 154501 to 154750)
## Processing batch 620 of 693 (features 154751 to 155000)
## Processing batch 621 of 693 (features 155001 to 155250)
## Processing batch 622 of 693 (features 155251 to 155500)
## Processing batch 623 of 693 (features 155501 to 155750)
## Processing batch 624 of 693 (features 155751 to 156000)
## Processing batch 625 of 693 (features 156001 to 156250)
## Processing batch 626 of 693 (features 156251 to 156500)
## Processing batch 627 of 693 (features 156501 to 156750)
## Processing batch 628 of 693 (features 156751 to 157000)
## Processing batch 629 of 693 (features 157001 to 157250)
## Processing batch 630 of 693 (features 157251 to 157500)
## Processing batch 631 of 693 (features 157501 to 157750)
## Processing batch 632 of 693 (features 157751 to 158000)
## Processing batch 633 of 693 (features 158001 to 158250)
## Processing batch 634 of 693 (features 158251 to 158500)
## Processing batch 635 of 693 (features 158501 to 158750)
## Processing batch 636 of 693 (features 158751 to 159000)
## Processing batch 637 of 693 (features 159001 to 159250)
## Processing batch 638 of 693 (features 159251 to 159500)
## Processing batch 639 of 693 (features 159501 to 159750)
## Processing batch 640 of 693 (features 159751 to 160000)
## Processing batch 641 of 693 (features 160001 to 160250)
## Processing batch 642 of 693 (features 160251 to 160500)
## Processing batch 643 of 693 (features 160501 to 160750)
## Processing batch 644 of 693 (features 160751 to 161000)
## Processing batch 645 of 693 (features 161001 to 161250)
## Processing batch 646 of 693 (features 161251 to 161500)
## Processing batch 647 of 693 (features 161501 to 161750)
## Processing batch 648 of 693 (features 161751 to 162000)
## Processing batch 649 of 693 (features 162001 to 162250)
## Processing batch 650 of 693 (features 162251 to 162500)
## Processing batch 651 of 693 (features 162501 to 162750)
## Processing batch 652 of 693 (features 162751 to 163000)
## Processing batch 653 of 693 (features 163001 to 163250)
## Processing batch 654 of 693 (features 163251 to 163500)
## Processing batch 655 of 693 (features 163501 to 163750)
## Processing batch 656 of 693 (features 163751 to 164000)
## Processing batch 657 of 693 (features 164001 to 164250)
## Processing batch 658 of 693 (features 164251 to 164500)
## Processing batch 659 of 693 (features 164501 to 164750)
## Processing batch 660 of 693 (features 164751 to 165000)
## Processing batch 661 of 693 (features 165001 to 165250)
## Processing batch 662 of 693 (features 165251 to 165500)
## Processing batch 663 of 693 (features 165501 to 165750)
## Processing batch 664 of 693 (features 165751 to 166000)
## Processing batch 665 of 693 (features 166001 to 166250)
## Processing batch 666 of 693 (features 166251 to 166500)
## Processing batch 667 of 693 (features 166501 to 166750)
## Processing batch 668 of 693 (features 166751 to 167000)
## Processing batch 669 of 693 (features 167001 to 167250)
## Processing batch 670 of 693 (features 167251 to 167500)
## Processing batch 671 of 693 (features 167501 to 167750)
## Processing batch 672 of 693 (features 167751 to 168000)
## Processing batch 673 of 693 (features 168001 to 168250)
## Processing batch 674 of 693 (features 168251 to 168500)
## Processing batch 675 of 693 (features 168501 to 168750)
## Processing batch 676 of 693 (features 168751 to 169000)
## Processing batch 677 of 693 (features 169001 to 169250)
## Processing batch 678 of 693 (features 169251 to 169500)
## Processing batch 679 of 693 (features 169501 to 169750)
## Processing batch 680 of 693 (features 169751 to 170000)
## Processing batch 681 of 693 (features 170001 to 170250)
## Processing batch 682 of 693 (features 170251 to 170500)
## Processing batch 683 of 693 (features 170501 to 170750)
## Processing batch 684 of 693 (features 170751 to 171000)
## Processing batch 685 of 693 (features 171001 to 171250)
## Processing batch 686 of 693 (features 171251 to 171500)
## Processing batch 687 of 693 (features 171501 to 171750)
## Processing batch 688 of 693 (features 171751 to 172000)
## Processing batch 689 of 693 (features 172001 to 172250)
## Processing batch 690 of 693 (features 172251 to 172500)
## Processing batch 691 of 693 (features 172501 to 172750)
## Processing batch 692 of 693 (features 172751 to 173000)
## Processing batch 693 of 693 (features 173001 to 173023)
## Reprojecting results back to original CRS...
# Step 1B: Spatial join to find accidents within construction buffers
cat("Finding accidents within construction buffers...\n")
## Finding accidents within construction buffers...
spatial_matches <- df.acc.sf %>%
# Prepare accident data
mutate(accident_id = if("ID" %in% names(.)) ID else row_number(),
accident_severity = if("Severity" %in% names(.)) Severity else NA_integer_,
accident_time = Start_Time) %>%
# Select only needed columns
select(accident_id, accident_severity, accident_time, geometry) %>%
# Spatial join with construction buffers
st_join(construction_buffers, join = st_within) %>%
# Filter for accidents within temporal range of construction
filter(!is.na(construction_id) &
accident_time >= start_time &
accident_time <= end_time) %>%
# Select final columns
select(accident_id, accident_severity, accident_time, construction_id)
# Step 1B-L: Spatial join to find accidents within construction line buffers
cat("Finding accidents within construction line buffers...\n")
## Finding accidents within construction line buffers...
line_spatial_matches <- df.acc.sf %>%
# Prepare accident data
mutate(accident_id = if("ID" %in% names(.)) ID else row_number(),
accident_severity = if("Severity" %in% names(.)) Severity else NA_integer_,
accident_time = Start_Time) %>%
# Select only needed columns
select(accident_id, accident_severity, accident_time, geometry) %>%
# Spatial join with construction line buffers
st_join(construction_line_buffers, join = st_within) %>%
# Filter for accidents within temporal range of construction
filter(!is.na(construction_id) &
accident_time >= start_time &
accident_time <= end_time) %>%
# Select final columns
select(accident_id, accident_severity, accident_time, construction_id, segment_length_m)
# Step 2: Count construction sites per accident
cat("Counting construction sites per accident...\n")
## Counting construction sites per accident...
construction_counts <- spatial_matches %>%
# Convert to regular dataframe (don't need geometry anymore)
st_set_geometry(NULL) %>%
# Group and count
group_by(accident_id) %>%
summarize(nearby_construction_count = n())
# Step 2-L: Count construction line sites per accident
cat("Counting construction line sites per accident...\n")
## Counting construction line sites per accident...
line_construction_counts <- line_spatial_matches %>%
# Convert to regular dataframe (don't need geometry anymore)
st_set_geometry(NULL) %>%
# Group and count
group_by(accident_id) %>%
summarize(nearby_line_construction_count = n())
# Step 3: Final analysis table - one construction site per accident
cat("Creating final analysis tables...\n")
## Creating final analysis tables...
# Create a function to randomly select one construction site per accident
select_random_construction <- function(df) {
df %>%
group_by(accident_id) %>%
slice_sample(n = 1) %>%
ungroup()
}
# Apply for point construction sites
accident_construction_analysis <- spatial_matches %>%
st_set_geometry(NULL) %>%
# Join with counts
left_join(construction_counts, by = "accident_id") %>%
# Add flags
mutate(
construction_type = 'POINT',
temporal_overlap = 1,
is_near_active_construction = 1
) %>%
# Select one construction site per accident randomly
select_random_construction()
# Apply for line construction sites
line_accident_construction_analysis <- line_spatial_matches %>%
st_set_geometry(NULL) %>%
# Join with counts
left_join(line_construction_counts, by = "accident_id") %>%
# Add flags
mutate(
temporal_overlap = 1,
is_near_active_construction = 1
) %>%
# Select one construction site per accident randomly
select_random_construction()
# Step 4-L: Calculate accident rates by segment length
cat("Calculating accident rates by segment length...\n")
## Calculating accident rates by segment length...
construction_segment_accident_rates <- df.const.lines_with_length %>%
# Ensure we have an ID column
mutate(construction_id = if("ID" %in% names(.)) ID else row_number()) %>%
# Left join with accident analysis
left_join(
line_accident_construction_analysis %>%
group_by(construction_id) %>%
summarize(accident_count = n()),
by = "construction_id"
) %>%
# Replace NA counts with 0
mutate(accident_count = replace_na(accident_count, 0)) %>%
# Calculate accidents per km
mutate(accidents_per_km = accident_count / (segment_length_m / 1000))
# Return to sequential processing
future::plan(future::sequential)
# Total accidents summary - for comparison
total_accidents <- nrow(df.acc.sf)
accidents_near_construction <- nrow(accident_construction_analysis)
cat("Total accidents in dataset:", total_accidents, "\n")
## Total accidents in dataset: 341876
cat("Accidents near active construction:", accidents_near_construction, "\n")
## Accidents near active construction: 59182
cat("Percentage of accidents near active construction: ",
round(accidents_near_construction/total_accidents*100, 2), "%\n")
## Percentage of accidents near active construction: 17.31 %
# Get statistics on construction zones
accidents_per_zone <- construction_segment_accident_rates %>%
filter(accident_count > 0) %>%
select(construction_id, accident_count, geometry)
cat("Construction zones with accidents:", nrow(accidents_per_zone), "\n")
## Construction zones with accidents: 12259
cat("Maximum accidents in a single construction zone:", max(accidents_per_zone$accident_count), "\n")
## Maximum accidents in a single construction zone: 695
cat("Average accidents per construction zone:", round(mean(accidents_per_zone$accident_count), 2), "\n")
## Average accidents per construction zone: 8.25
# Join accident data with construction info
accidents_with_construction <- df.acc.sf %>%
mutate(accident_id = if("ID" %in% names(.)) ID else row_number()) %>%
left_join(
accident_construction_analysis %>%
select(accident_id, construction_id, nearby_construction_count, construction_type),
by = "accident_id"
) %>%
mutate(near_construction = ifelse(is.na(construction_id), 0, 1))
# Construction density statistics
construction_density_stats <- accident_construction_analysis %>%
group_by(nearby_construction_count) %>%
summarize(accident_count = n()) %>%
arrange(nearby_construction_count)
print(construction_density_stats)
## # A tibble: 93 × 2
## nearby_construction_count accident_count
## <int> <int>
## 1 1 32123
## 2 2 11572
## 3 3 5336
## 4 4 2774
## 5 5 1820
## 6 6 1117
## 7 7 794
## 8 8 540
## 9 9 492
## 10 10 327
## # ℹ 83 more rows
# Severity analysis near line construction
severity_by_construction <- line_accident_construction_analysis %>%
group_by(accident_severity) %>%
summarize(count = n()) %>%
arrange(accident_severity)
# Comparison of accident severity near vs. away from construction
accidents_near <- accidents_with_construction %>%
filter(near_construction == 1) %>%
st_set_geometry(NULL) %>%
mutate(location = "Near construction") %>%
select(Severity, location)
accidents_away <- accidents_with_construction %>%
filter(near_construction == 0) %>%
st_set_geometry(NULL) %>%
mutate(location = "Away from construction") %>%
select(Severity, location)
severity_comparison <- bind_rows(accidents_near, accidents_away) %>%
group_by(Severity, location) %>%
summarize(count = n(), .groups = "drop") %>%
arrange(Severity, location)
# Time-based analysis
temporal_analysis <- line_accident_construction_analysis %>%
mutate(month = floor_date(accident_time, "month")) %>%
group_by(month) %>%
summarize(accident_count = n()) %>%
arrange(month)
The code below implements the PostGIS functionality directly in R.
# Visualize construction zones with accident counts
# First, store our plot in a variable
accident_zones_plot <- ggplot() +
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
# Arrange data in descending order so high frequency zones are plotted on top
geom_sf(data = accidents_per_zone %>% arrange(accident_count),
aes(color = accident_count), size = 1.5) +
scale_color_viridis_c() +
theme_minimal() +
labs(title = "Accident Counts within Construction Zones (2021)")
print(accident_zones_plot)
# Then save it using ggsave
ggsave(filename = "imgs/accident_counts_construction_zones.png",
plot = accident_zones_plot,
width = 10, # width in inches
height = 8, # height in inches
dpi = 300) # resolution
# Static map with construction line segments
ggplot() +
geom_sf(data = ca_roads, color = "gray80", size = 0.1) +
geom_sf(data = df.const.lines %>% filter(State == "CA"),
color = "orange", size = 1) +
theme_minimal() +
labs(title = "US Construction Segments (2021)")
# Interactive map with construction segments focused on California
construction_segment_map <- leaflet() %>%
addTiles() %>%
addPolylines(data = df.const.lines,
color = "orange",
weight = 3,
opacity = 0.7,
popup = ~paste("ID:", ID, "<br>Duration:", duration)) %>%
setView(lng = -119.4179, lat = 36.7783, zoom = 6) %>% # Center on California
setMaxBounds(lng1 = -124.6, lat1 = 42.0, # Northwest corner of CA
lng2 = -114.1, lat2 = 32.5) # Southeast corner of CA
# Display the map
construction_segment_map